import java.util.Date;


public class Athlete {
	private int race_number;
	private String name;
	private String phone;
	private int lastPassage;
	private Date[] times;
	
	public Athlete(int race_number, String name, String phone) {
		this.race_number = race_number;
		this.name = name;
		this.phone = phone;
		this.lastPassage = Race.NOT_STARTED;
		this.times = new Date[Race.CHECKPOINTS];
	}

	public int getRace_number() {
		return race_number;
	}

	public String getName() {
		return name;
	}

	public String getPhone() {
		return phone;
	}

	public Date getTime(int checkPoint) {
		return times[checkPoint];
	}
	
	public int getLastPassage(){
		return lastPassage;
	}
	
	public long currentTime (){
		long time;
		
		switch (lastPassage){
			case Race.NOT_STARTED: time = -1; break;
			case 0: time = 0; break;
			default: time = times[lastPassage].getTime() - times[0].getTime();
		}
		
		return time;
	}
	
	public long checkPoint (int checkPoint, Date time){
		if (checkPoint < lastPassage)
			return Race.ERROR_PREVIOUS_CHECKPOINT;
		
		if (checkPoint == lastPassage)
			return Race.ERROR_SAME_CHECKPOINT;
		
		if (checkPoint > lastPassage + 1)
			return Race.ERROR_SKIPPED_CHECKPOINT;
		
		times[checkPoint] = time;		
		lastPassage = checkPoint;
		
		return getPartial(checkPoint);
	}
	
	public long getPartial (int checkPoint) {
		if (checkPoint == 0)
			return 0;
		
		return times[checkPoint].getTime() - times[checkPoint - 1].getTime();
	}
	
	public String getStringTime (int point){
		if (point>lastPassage)
			return "---";
		long timeinmillis = times[point].getTime() - times[0].getTime();
		timeinmillis =  timeinmillis/1000;
		int seconds = (int) timeinmillis%60;
		timeinmillis = timeinmillis/60;
		int minutes = (int) timeinmillis%60;
		int hours = (int) timeinmillis/60;
		
		String strSeconds = seconds<10 ? "0"+seconds : ""+seconds;
		String strMinutes = minutes<10 ? "0"+minutes : ""+minutes;
		
		return (hours+":"+strMinutes+":"+strSeconds);
	}
	
	
}
